/*
 * discoverAgent.h
 *
 *  Created on: 2011-8-17
 *      Author: fufan
 */

#ifndef DISCOVERAGENT_H_
#define DISCOVERAGENT_H_

#include <QtGui>
#include "ui_QSnmp.h"
#include "snmp_pp/snmp_pp.h"
#include "snmp_pp/snmpmsg.h"
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>


#define PORT 161
#define READCOMMUNITY "public"
#define VERSIONS 2
#define TIMEOUT 5

class DiscoverThread;

class DiscoverSnmp : public Snmp
{
public:
	DiscoverSnmp(int &status) :Snmp(status){};
	void discover(const QString &startIp, const QString &endIp, const OctetStr &read_community,
			const snmp_version &version, int timeoutSec, DiscoverThread *thread);


	bool isRun;
};

class DiscoverThread : public QThread
{
	Q_OBJECT
public:
	DiscoverThread(QLineEdit *startIp, QLineEdit *endIp);
	void run();
	void progress();
	void getAgentInfo(const Pdu &pdu,const UdpAddress &address, const snmp_version version);
	DiscoverSnmp *getSnmp();

signals:
	void sendProgressValue(const int value);
	void sendAgentInfo(const QStringList &agentInfo);
	void signalStartStop(int flag);

private:
	int progressValue;
	QLineEdit *startIp;
	QLineEdit *endIp;
	DiscoverSnmp *discoverSnmp;
};

class DiscoverAgent : public QObject
{
	Q_OBJECT
public:
	DiscoverAgent(Ui::MainWindow *mainw);
private slots:
	void startDiscover();
	void stopDiscover();
	void createMenu(const QPoint &point);
	void addToAgent();
	void deleteAgent();
	void showAgentInfo(const QStringList &agentInfo);
	void setProgressValue(const int value);
	void setStartStop(int flag);

private:
	QComboBox *agentBox;
	QPushButton *startDiscoverBtn;
	QPushButton *stopDiscoverBtn;
	QTableWidget *discoveryResult;
	QProgressBar *discoveryProgress;
	DiscoverThread *discoverThread;


};

#endif /* DISCOVERAGENT_H_ */
